// plugin_executor_raw.cpp 
#include "behaviortree_cpp/bt_factory.h"
#include "behaviortree_cpp/xml_parsing.h"
#include <dlfcn.h>
static const char* xml_text = R"(

// clang-format off
 <root BTCPP_format="4" main_tree_to_execute="MainTree" >
  <BehaviorTree ID="MainTree">
    <Sequence>
        <Script   code="vect:='1,2,3,4'"/>
        <PrintVector value="{vect}"/>;
        <SubTree ID="MySub" v4="{vect}"/>
    </Sequence>
  </BehaviorTree>

  <BehaviorTree ID="MySub">
    <PrintVector value="{v4}"/>;
  </BehaviorTree>
 </root>
 )";
// clang-format on

int main() {
    BT::BehaviorTreeFactory factory;
    // 1. 加载插件动态库
    void* handle = dlopen("./test_plugin_action.so", RTLD_LAZY);
    // 2. 查找注册函数（固定名称）
    using RegisterFunc = void(*)(BT::BehaviorTreeFactory&);
    auto register_func = (RegisterFunc)dlsym(handle, "BT_RegisterNodesFromPlugin");
    // 3. 调用注册函数
    register_func(factory);
    // 4. 现在可以使用插件中的节点了
    auto tree = factory.createTreeFromText(xml_text);
    
    tree.tickWhileRunning();
    
    dlclose(handle);
    return 0;
}